/********************************************************************
	Rhapsody	: 7.5 
	Login		: KBE
	Component	: DefaultComponent 
	Configuration 	: CodeConfig
	Model Element	: RequestPatient
//!	Generated Date	: Tue, 25, Sep 2012  
	File Path	: DefaultComponent\CodeConfig\RequestPatient.cpp
*********************************************************************/

//## auto_generated
#include "RequestPatient.h"
//## auto_generated
#include "Reactor.h"
//## auto_generated
#include "LF_EventHandler.h"
//## package Default

//## class RequestPatient
RequestPatient::RequestPatient(Reactor * reactor) {
    //#[ operation RequestPatient(Reactor *)
    //#[ operation LogEvent(Reactor*,SOCK_Stream)
    //setPeer_stream_(stream);
    //handle = (HANDLE)stream->get_handle();
    itsReactor = reactor;
    //itsReactor->registerHandler(*this, READ_EVENT);
    //#]
}

RequestPatient::RequestPatient() {
}

RequestPatient::~RequestPatient() {
}

void RequestPatient::getPatientInfo() {
    //#[ operation getPatientInfo()
    printf("Input CPR > ");
    scanf("%s", buffer_);
    getPeer_stream_()->send_n(buffer_, 100, 0);
    //#]
}

void RequestPatient::handleEvent(HANDLE h, Event_Type& et) {
    //#[ operation handleEvent(HANDLE,Event_Type)
    if (et == type) {
    	int n = getPeer_stream_()->recv_n(buffer_, sizeof(buffer_), 0);
    	if (n > 0) { 
    		PatientAction();
    	}
    	else 
    	{
    		//itsReactor->removeHandler(*this, type);
    		//delete this; // Deallocate ourselves
    	}
    }
    //#]
}

void RequestPatient::PatientAction() {
    //#[ operation PatientAction()
    printf("Patient: %s\n", buffer_);
    //#]
}

char RequestPatient::getBuffer_(int i1) const {
    return buffer_[i1];
}

void RequestPatient::setBuffer_(int i1, char p_buffer_) {
    buffer_[i1] = p_buffer_;
}

int RequestPatient::getState_() const {
    return state_;
}

void RequestPatient::setState_(int p_state_) {
    state_ = p_state_;
}

/*********************************************************************
	File Path	: DefaultComponent\CodeConfig\RequestPatient.cpp
*********************************************************************/
